package it.secse.idmadaption.plugin.util;


import org.apache.ws.security.WSPasswordCallback;

import it.secse.idmadaption.credential.UsrPassCredentialData;
import it.secse.idmadaption.engine.IDMAdapter;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;

import java.io.IOException;

public class PWCBHandlerClient implements CallbackHandler {

    public void handle(Callback[] callbacks) throws IOException,
            UnsupportedCallbackException {
        for (int i = 0; i < callbacks.length; i++) {
                   	
            WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i];
            UsrPassCredentialData cred = (UsrPassCredentialData) IDMAdapter.getCredential();
            if (cred.getUserName().equals(pwcb.getIdentifer()))
            	pwcb.setPassword(cred.getPassword());
       
        }
    }

}

